package com.pokeoffice.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.border.LineBorder;

import com.pokeoffice.client.Client;
import com.pokeoffice.client.Session;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class NurseHome extends JPanel {
	private static final long serialVersionUID = 2888944289656868787L;
	private JTextField textField;
	private Session session;
	private JPanel subPanel;
	
	public NurseHome(final Session session) {
		this.session = session;
		
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JButton btnSearch = new JButton("Search");
		btnSearch.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Search
			}
		});
		add(btnSearch);
		
		JLabel lblAdmin = new JLabel("Nurse");
		springLayout.putConstraint(SpringLayout.EAST, lblAdmin, -30, SpringLayout.EAST, this);
		lblAdmin.setFont(new Font("Dialog", Font.BOLD, 20));
		springLayout.putConstraint(SpringLayout.NORTH, lblAdmin, 10, SpringLayout.NORTH, this);
		add(lblAdmin);
		
		JButton btnUsers = new JButton("All Users");
		springLayout.putConstraint(SpringLayout.WEST, btnUsers, 80, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, btnUsers, 230, SpringLayout.WEST, this);
		btnUsers.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO All the Users
			}
		});
		
		springLayout.putConstraint(SpringLayout.WEST, btnSearch, 0, SpringLayout.WEST, btnUsers);
		springLayout.putConstraint(SpringLayout.EAST, btnSearch, 0, SpringLayout.EAST, btnUsers);
		springLayout.putConstraint(SpringLayout.SOUTH, btnSearch, -20, SpringLayout.NORTH, btnUsers);
		springLayout.putConstraint(SpringLayout.SOUTH, btnUsers, -30, SpringLayout.SOUTH, this);
		add(btnUsers);
		
		subPanel = new JPanel();
		springLayout.putConstraint(SpringLayout.NORTH, subPanel, 55, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.SOUTH, subPanel, -125, SpringLayout.SOUTH, this);
		subPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
		springLayout.putConstraint(SpringLayout.WEST, subPanel, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, subPanel, -30, SpringLayout.EAST, this);
		add(subPanel);
		
		JButton btnVisit = new JButton("Visit");
		btnVisit.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Professor's view
			}
		});
		springLayout.putConstraint(SpringLayout.WEST, btnVisit, 30, SpringLayout.EAST, btnUsers);
		springLayout.putConstraint(SpringLayout.SOUTH, btnVisit, 0, SpringLayout.SOUTH, btnUsers);
		springLayout.putConstraint(SpringLayout.EAST, btnVisit, 180, SpringLayout.EAST, btnUsers);
		add(btnVisit);
		
		JButton btnCreate = new JButton("User");
		btnCreate.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				subPanel.add(new CreateUser(session));
				session.display();
				// TODO Create
			}
		});
		springLayout.putConstraint(SpringLayout.WEST, btnCreate, 30, SpringLayout.EAST, btnVisit);
		springLayout.putConstraint(SpringLayout.SOUTH, btnCreate, 0, SpringLayout.SOUTH, btnUsers);
		springLayout.putConstraint(SpringLayout.EAST, btnCreate, 180, SpringLayout.EAST, btnVisit);
		add(btnCreate);
		
		JButton btnLogout = new JButton("Logout");
		btnLogout.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				session.logout();
			}
		});
		springLayout.putConstraint(SpringLayout.WEST, btnLogout, 30, SpringLayout.EAST, btnCreate);
		springLayout.putConstraint(SpringLayout.SOUTH, btnLogout, 0, SpringLayout.SOUTH, btnUsers);
		springLayout.putConstraint(SpringLayout.EAST, btnLogout, 180, SpringLayout.EAST, btnCreate);
		add(btnLogout);
		
		textField = new JTextField();
		springLayout.putConstraint(SpringLayout.WEST, textField, 30, SpringLayout.EAST, btnSearch);
		springLayout.putConstraint(SpringLayout.SOUTH, textField, 0, SpringLayout.SOUTH, btnSearch);
		springLayout.putConstraint(SpringLayout.EAST, textField, 0, SpringLayout.EAST, btnLogout);
		add(textField);
		textField.setColumns(10);
		
		Dimension size = new Dimension(Client.WIDTH + 60, Client.HEIGHT + 180);
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
	}
	
	
}
